package InvestmentPojo;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.java.com.mkyong.common.action.UserAction;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import ImmovableIndia.serviceManagerImpl;
import adminLoginPack.FemaUtilAuthenticate;



public class UIFormAction extends Action {

	private static final Logger logger = Logger.getLogger(UIFormAction.class);

	  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		 
		 
		  Properties props = new Properties(System.getProperties());
		 
		  String value = "";
		  FileInputStream fis ;
		  StringBuffer sb = new StringBuffer();
		  String str123 = null;
		  String serviceId = null;
		  String method = null;
		  String showToolPage = null;
		  String forwardPage = null; 
		  String returnTableData = null;
		  try{
			  
			  
		 
		  
		  serviceManagerImpl smp = new serviceManagerImpl();
		  
		  String UserIDForservice = null != request.getParameter("UserIDForservice")? request.getParameter("UserIDForservice"):"";
		  showToolPage = null != request.getParameter("shoowMethodName")? request.getParameter("shoowMethodName"):"";
		  method = null != request.getParameter("a")?request.getParameter("a"):"";
		  
		  String userId = null != request.getParameter("UserID")? request.getParameter("UserID"):"";
		  
		  if("".equals(userId)){
			  userId = null != request.getSession().getAttribute("UserID")?(String)request.getSession().getAttribute("UserID"):"";
		  }
		  
		  InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("/webdefault/ContactUs.jsp");
          //Properties         applicationConfigProperties = new Properties();
  // applicationConfigProperties.load(inputStream);
		  
		  String path = request.getSession().getServletContext().getRealPath("/");
		  
			
			if(!"".equals(showToolPage) && showToolPage.equals("showToolPage")){
				
						  int serviceNo = Integer.parseInt(UserIDForservice);
						  String defaultPage = "/ServiceShowPages/defaultServiceShowPage"+serviceNo+".html";
						  logger.info(serviceNo);
						  switch(serviceNo){
						  case 1:
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","FDITools.jsp");
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("TOOLName", "FOREIGN DIRECT INVESTMENT");
							  request.setAttribute("dropDownList", (smp.getDropDownList("tableName", UserIDForservice)));
							  logger.info("FDITOOL");
							  break;
						  case 2 :
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","ImmovableInIndia.jsp");
							  request.setAttribute("TOOLName", "IMMOVABLE PROPERTY IN INDIA");
							  request.setAttribute("UserID",userId);
							  request.setAttribute("dropDownList", (smp.getDropDownList("tableName", "3")));
							  logger.info("immovable");
							  break;
						  case 3 :
							 
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","BranchLOProjectOfficeInIndia.jsp");
							  request.setAttribute("TOOLName", "BRANCH/LIAISON OFFICE/PROJECT OFFICE IN INDIA");
							  request.setAttribute("UserID",userId);
							  break;
							  
						  case 4 :
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("showUserToolPage","BorrowingInRupees.jsp");
							  request.setAttribute("TOOLName", "BORROWING IN RUPEES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 5 :
							  
							  request.setAttribute("showServiceName", "EXTERNAL COMMERCIAL BORROWING");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "EXTERNAL COMMERCIAL BORROWING");
							  request.setAttribute("UserID",userId);
							  break;
						  case 6 :
							  request.setAttribute("showServiceName", "EXPORT OF GOODS &SERVICES");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "EXPORT OF GOODS & SERVICES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 7 :
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","ODIIndividual.jsp");
							  request.setAttribute("TOOLName", "OVERSEAS DIRECT INVESTMENT");
							  request.setAttribute("UserID",userId);
							  break;
						  case 8 :
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","ImmovableProOutSideIndia.jsp");
							  request.setAttribute("TOOLName", "IMMOVABLE PROPERTY ABROAD");
							  request.setAttribute("UserID",userId);
							  break;
						  case 9 :
							  request.setAttribute("showServiceName", "BRANCH OFFICE OUTSIDE INDIA");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "BRANCH OFFICE OUTSIDE INDIA");
							  request.setAttribute("UserID",userId);
							  break;
						  case 10 :
							  request.setAttribute("showServiceName", "IMPORT OF GOODS AND SERVICES");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "IMPORT OF GOODS AND SERVICES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 11 :
							  request.setAttribute("showServiceName", "FOREIGN EXCHANGE REMITTANCES");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","ForeignExchange.jsp");
							  request.setAttribute("TOOLName", "FOREIGN EXCHANGE REMITTANCES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 12 :
							  request.setAttribute("showServiceName", "TOOLS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","ForeignExchange.jsp");
							  request.setAttribute("TOOLName", "FOREIGN EXCHANGE REMITTANCES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 13 :
							  request.setAttribute("showServiceName", "FORMS & FORMATS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", "FormsNFormats.jsp");
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","FormsNFormats.jsp");
							  request.setAttribute("TOOLName", "FORMS & FORMATS");
							  request.setAttribute("UserID",userId);
							  break;
						  case 14 :
							  request.setAttribute("showServiceName", "COMPOUNDING OF OFFENCES");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "COMPOUNDING OF OFFENCES");
							  request.setAttribute("UserID",userId);
							  break;
						  case 15 :
							  request.setAttribute("showServiceName", "GOVT APPROVALS");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "GOVT APPROVALS");
							  request.setAttribute("UserID",userId);
							  break;
						  case 16 :
							  request.setAttribute("showServiceName", "Service 4");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "");
							  request.setAttribute("UserID",userId);
							  break;
						  case 17 :
							  request.setAttribute("showServiceName", "Service 5");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "");
							  request.setAttribute("UserID",userId);
							  break;
						  case 18 :
							  request.setAttribute("showServiceName", "Service 6");
							  request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("defaultShowServicePage", defaultPage);
							  request.setAttribute("UserID",request.getSession().getAttribute("UserID"));
							  request.setAttribute("showUserToolPage","");
							  request.setAttribute("TOOLName", "");
							  request.setAttribute("UserID",userId);
							  break;
							 
						 default :
							 request.setAttribute("UserIDForservice", UserIDForservice);
							  request.setAttribute("UserID",userId);
							  
							  
						  }
						  
						  forwardPage = "success";	 
				 
				
			}
			
			 String str = "";
		  if(null != method){
			  
			
		  if(method.trim().equals("Notifications")){
			  
			  request.setAttribute("showUserToolPage", "");
			  
			  returnTableData = smp.getNotificationData(UserIDForservice, "notification" , userId);
			  
			   
			  request.setAttribute("TOOL", "1");
			  request.setAttribute("UserIDForservice", UserIDForservice);
			  logger.debug("notification data Loading");
			 
		  }else if(method.trim().equals("Articles")){
			  returnTableData = smp.getArticlesData(UserIDForservice, "articles", "");
			  logger.debug("Articles data Loading");
			 
		  }else if(method.trim().equals("Circulars") || method.trim().equals("MasterCirculars")){
			  
			  if(method.trim().equals("MasterCirculars")){
			  returnTableData = smp.getsMasterCircularsData(UserIDForservice, "master_circulars", "");
			  logger.debug("MasterCirculars data Loaded"+UserIDForservice);
			  }else {
				  logger.debug("Circulars data Loading"+UserIDForservice);
				  returnTableData = smp.getCircularsData(UserIDForservice, "circulars", "");
			  }
			  
			 
			  
			   
		  }else if(method.trim().equals("FAQ")){
			  returnTableData = smp.getFAQDataLoading(UserIDForservice, "faq", "");
			  logger.debug("faqs Loaded successfuly..."+UserIDForservice);
			 
		  }else if(method.trim().equals("PressNotes")){
			  
			  returnTableData = smp.getPressNotesDataLoading(UserIDForservice, "pressnotes", "");
			  logger.debug("pressnotes Loaded successfuly..."+UserIDForservice);
			  
		  }else if(method.trim().equals("FormsNChecklists")){
			  returnTableData = smp.getFormsNCheckListsDataLoading(UserIDForservice, "FormsNCheckLists", path);
			  logger.debug("FormsNCheckLists......Loaded Successfully."+UserIDForservice);
			  
		  }else if(method.trim().equals("DEFINITIONS")){
			  
			  returnTableData = smp.getDefinitionsDataLoading(UserIDForservice, "definitions", "");
			  logger.debug("DEFINITIONS......Loaded Successfully."+UserIDForservice);
			  
		  }else if(method.trim().equals("CaseLaws")){
			  returnTableData = smp.getCommingSoonData();
		  }else if(method.trim().equals("withoutuser")){
			  
			  returnTableData = smp.getWithoutUserData(); 
			  str = returnTableData;
			  
		  }else {
			  if("".equals(showToolPage) && !showToolPage.equals("showToolPage")){
				FemaUtilAuthenticate femaUtil = new FemaUtilAuthenticate();
				  
				  boolean isUserExist = femaUtil.isUserExist(request, response,userId);
				  if(!isUserExist){
					  forwardPage =  "authfailed";
				  }
			  }
			}
         

		 
             
              if(method.trim().equals("Notifications") || method.trim().equals("CaseLaws")  || method.trim().equals("Articles") || method.trim().equals("Circulars") || method.trim().equals("MasterCirculars") || method.trim().equals("PressNotes")  || method.trim().equals("FormsNChecklists") || method.trim().equals("FAQ") || method.trim().equals("DEFINITIONS")){
            	  
            	  fis  = new FileInputStream(path+"/webDefault/ContactUs.jsp");

        		  try {
                     
                      int content;
                      while ((content = fis.read()) != -1) {
                          // convert to char and display it
                          str += (char) content;
                      }
                  }catch(Exception e){
                	  System.out.println(e);
                	  logger.debug(e);
                  }
        		  System.out.println("After reading file");
        		  logger.debug(returnTableData);
            	  response.getWriter().write(returnTableData);
              

              } 
              
              if(method.trim().equals("4") || method.trim().equals("3") || method.trim().equals("6") || method.trim().equals("8") || method.trim().equals("withoutuser")){
            	  response.getWriter().write(str); 
              }
         
		  }
		 
	    
		  }catch(Exception e) {
			  logger.debug(e);
			  e.printStackTrace();
			  logger.error(e);
		  }
	
		  return mapping.findForward(forwardPage); // Not forwarding to anywhere, response is fully-cooked	  
	  }
}
